package com.aspose.cells;

import java.util.ArrayList;

public class FillFormat {
   private Object d;
   Workbook a;
   Object b;
   private int e = 0;
   boolean c = false;

   public int getType() {
      return this.e;
   }

   public void setType(int value) {
      this.e = value;
      switch(value) {
      case 0:
         this.d = null;
         break;
      case 1:
         this.d = null;
         break;
      case 2:
         if (this.d == null || !(this.d instanceof SolidFill)) {
            this.d = new SolidFill(this.b, this.a);
         }

         this.c();
         break;
      case 3:
         if (this.d == null || !(this.d instanceof GradientFill)) {
            this.d = new GradientFill(this.b, this.a);
         }

         this.c();
         break;
      case 4:
         if (this.d == null || !(this.d instanceof TextureFill)) {
            this.d = new TextureFill(this.b, this.a);
         }

         this.c();
         break;
      case 5:
         if (this.d == null || !(this.d instanceof PatternFill)) {
            this.d = new PatternFill(this.b, this.a);
         }

         this.c();
         break;
      case 6:
         this.d = null;
      }

   }

   int a() {
      int var1 = 100;
      if (this.getType() == 2) {
         var1 = this.getSolidFill().b();
      } else if (this.getType() == 4) {
         var1 = this.getTextureFill().e();
      } else if (this.getType() == 5) {
         var1 = this.getPatternFill().a();
      }

      return var1;
   }

   void a(int var1) {
      if (this.getType() == 2) {
         this.getSolidFill().a(var1);
      } else if (this.getType() == 4) {
         this.getTextureFill().c(var1);
      } else if (this.getType() == 5) {
         this.getPatternFill().a(var1);
      }

   }

   public double getTransparency() {
      return com.aspose.cells.b.a.zq.b((double)(100 - this.a()) / 100.0D, 2);
   }

   public void setTransparency(double value) {
      if (value >= 0.0D && value <= 1.0D) {
         int var3 = 100 - (int)(value * 100.0D);
         this.a(var3);
         if (this.getType() == 3) {
            GradientFill var4 = this.getGradientFill();
            if (var4.getGradientStops() != null && var4.getGradientStops().getCount() > 0) {
               for(int var5 = 0; var5 < var4.getGradientStops().getCount(); ++var5) {
                  var4.getGradientStops().get(var5).a(var3);
               }
            }
         }

      } else {
         throw new CellsException(6, "Transparency must between 0.0 (opaque) and 1.0 (clear)");
      }
   }

   Object b() {
      return this.b;
   }

   FillFormat(Object parent, Workbook workbook) {
      this.b = parent;
      this.a = workbook;
   }

   FillFormat(MsoFillFormatHelper msoFillFormatHelper, Object parent, Workbook workbook, boolean is03To07) {
      this.b = parent;
      this.a = workbook;
      this.a(msoFillFormatHelper, is03To07);
   }

   /** @deprecated */
   public int getSetType() {
      switch(this.getType()) {
      case 1:
         return 0;
      case 2:
      default:
         return 0;
      case 3:
         return 1;
      case 4:
         return 2;
      case 5:
         return 3;
      }
   }

   /** @deprecated */
   public void setSetType(int value) {
      switch(value) {
      case 0:
         this.setType(1);
         break;
      case 1:
         this.setType(3);
         break;
      case 2:
         this.setType(4);
         break;
      case 3:
         this.setType(5);
      }

   }

   public GradientFill getGradientFill() {
      if (this.getType() == 3) {
         if (this.d == null || !(this.d instanceof GradientFill)) {
            this.d = new GradientFill(this.b, this.a);
            return (GradientFill)this.d;
         }

         if (this.d != null && this.d instanceof GradientFill) {
            return (GradientFill)this.d;
         }
      }

      return null;
   }

   public TextureFill getTextureFill() {
      if (this.getType() == 4) {
         if (this.d == null || !(this.d instanceof TextureFill)) {
            this.d = new TextureFill(this.b, this.a);
            return (TextureFill)this.d;
         }

         if (this.d != null && this.d instanceof TextureFill) {
            return (TextureFill)this.d;
         }
      }

      return null;
   }

   public SolidFill getSolidFill() {
      if (this.getType() == 2) {
         if (this.d == null || !(this.d instanceof SolidFill)) {
            this.d = new SolidFill(this.b, this.a);
            return (SolidFill)this.d;
         }

         if (this.d != null && this.d instanceof SolidFill) {
            return (SolidFill)this.d;
         }
      }

      return null;
   }

   public PatternFill getPatternFill() {
      if (this.getType() == 5) {
         if (this.d == null || !(this.d instanceof PatternFill)) {
            this.d = new PatternFill(this.b, this.a);
            return (PatternFill)this.d;
         }

         if (this.d != null && this.d instanceof PatternFill) {
            return (PatternFill)this.d;
         }
      }

      return null;
   }

   void c() {
      if (this.b != null && this.b instanceof Area) {
         ((Area)this.b).c();
      }

   }

   public int getGradientColorType() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         return this.getGradientFill().getGradientColorType();
      }
   }

   public int getGradientStyle() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         return this.getGradientFill().getGradientStyle();
      }
   }

   public Color getGradientColor1() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         int var1 = this.getGradientFill().getGradientColorType();
         if (var1 == 0) {
            throw new CellsException(7, "The gradient color 1 is not set.");
         } else {
            return this.getGradientFill().getGradientColor1();
         }
      }
   }

   public Color getGradientColor2() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         int var1 = this.getGradientFill().getGradientColorType();
         switch(var1) {
         case 0:
         case 1:
            throw new CellsException(7, "The gradient color 2 is not set.");
         default:
            return this.getGradientFill().getGradientColor2();
         }
      }
   }

   public double getGradientDegree() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         int var1 = this.getGradientFill().getGradientColorType();
         return var1 != 1 ? 0.0D : this.getGradientFill().getGradientDegree();
      }
   }

   public int getGradientVariant() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         return this.getGradientFill().getVariant();
      }
   }

   public int getPresetColor() {
      if (this.getType() != 3) {
         throw new CellsException(7, "Gradient option is not set.");
      } else {
         return this.getGradientFill().getPresetColor();
      }
   }

   public void setOneColorGradient(Color color, double degree, int style, int variant) {
      this.c();
      this.setType(3);
      this.getGradientFill().setOneColorGradient(color, degree, style, variant);
   }

   public void setTwoColorGradient(Color color1, Color color2, int style, int variant) {
      this.c();
      this.setType(3);
      this.getGradientFill().setTwoColorGradient(color1, color2, style, variant);
   }

   public void setTwoColorGradient(Color color1, double transparency1, Color color2, double transparency2, int style, int variant) {
      this.c();
      this.setType(3);
      this.getGradientFill().setTwoColorGradient(color1, transparency1, color2, transparency2, style, variant);
   }

   public void setPresetColorGradient(int presetColor, int style, int variant) {
      if (presetColor != 24) {
         this.c();
         this.setType(3);
         this.getGradientFill().setPresetColorGradient(presetColor, style, variant);
      }
   }

   public int getTexture() {
      return this.getType() != 4 ? 24 : this.getTextureFill().getType();
   }

   public void setTexture(int value) {
      if (value != 24) {
         this.setType(4);
         this.getTextureFill().setType(value);
         this.c();
      }
   }

   public int getPattern() {
      return this.getType() != 5 ? 50 : this.getPatternFill().getPattern();
   }

   public void setPattern(int value) {
      if (value != 50) {
         this.setType(5);
         this.getPatternFill().setPattern(value);
         this.c();
      }
   }

   void a(FillFormat var1, CopyOptions var2) {
      this.setType(var1.e);
      switch(this.e) {
      case 2:
         this.getSolidFill().a(var1.getSolidFill(), var2);
         break;
      case 3:
         this.getGradientFill().a(var1.getGradientFill());
         break;
      case 4:
         this.getTextureFill().a(var1.getTextureFill());
         break;
      case 5:
         this.getPatternFill().a(var1.getPatternFill());
         break;
      default:
         this.d = null;
      }

   }

   boolean a(FillFormat var1, zma var2) {
      if (this.getType() != var1.e) {
         return false;
      } else {
         switch(this.e) {
         case 2:
            if (!this.getSolidFill().a(var1.getSolidFill(), var2)) {
               return false;
            }
            break;
         case 3:
            if (!this.getGradientFill().b(var1.getGradientFill())) {
               return false;
            }
            break;
         case 4:
            if (!this.getTextureFill().b(var1.getTextureFill())) {
               return false;
            }
            break;
         case 5:
            if (!this.getPatternFill().b(var1.getPatternFill())) {
               return false;
            }
         }

         return true;
      }
   }

   public int getPictureFormatType() {
      return this.getType() == 4 && this.getTextureFill().getPicFormatOption() != null ? this.getTextureFill().getPicFormatOption().getType() : 0;
   }

   public void setPictureFormatType(int value) {
      if (this.getType() == 4) {
         if (this.getTextureFill().getPicFormatOption() == null) {
            this.getTextureFill().setPicFormatOption(new PicFormatOption());
         }

         this.getTextureFill().getPicFormatOption().setType(value);
      }
   }

   public double getScale() {
      return this.getType() == 4 && this.getTextureFill().getPicFormatOption() != null ? this.getTextureFill().getPicFormatOption().getScale() : 100.0D;
   }

   public void setScale(double value) {
      if (this.getType() == 4) {
         if (this.getTextureFill().getPicFormatOption() == null) {
            this.getTextureFill().setPicFormatOption(new PicFormatOption());
         }

         this.getTextureFill().getPicFormatOption().setScale(value);
      }
   }

   public byte[] getImageData() {
      return this.getType() == 4 ? this.getTextureFill().getImageData() : null;
   }

   public void setImageData(byte[] value) {
      this.setType(4);
      this.getTextureFill().setImageData(value);
      this.c();
   }

   void a(MsoFillFormatHelper var1, boolean var2) {
      if (!var1.a.k() || var2) {
         if (var1 != null) {
            byte var3 = 6;
            int var4 = (int)var1.g();
            int var5 = (int)(var1.i() * 100.0F);
            switch(var1.b()) {
            case 0:
               if (!var1.isVisible()) {
                  this.setType(1);
               } else {
                  this.setType(2);
                  this.getSolidFill().setColor(var1.getForeColor());
                  this.getSolidFill().a(var1.getBackColor());
                  this.getSolidFill().setTransparency(var1.getForeColorTransparency());
               }

               return;
            case 1:
               this.setPattern(var1.q());
               if (this.getPatternFill() != null) {
                  this.getPatternFill().setForegroundColor(var1.getForeColor());
                  this.getPatternFill().setBackgroundColor(var1.getBackColor());
               }

               return;
            case 2:
            case 3:
               int var26 = var1.n();
               byte[] var27 = var1.p();
               if (var26 != 0) {
                  this.setType(4);
                  this.getTextureFill().c = var26 - 1;
               } else if (var27 != null) {
                  this.setType(4);
                  this.getTextureFill().a(var27);
               } else {
                  this.setType(1);
               }

               if (var1.b() == 2) {
                  this.getTextureFill().setTilePicOption(new TilePicOption());
               }

               return;
            case 4:
            case 7:
               switch(var4) {
               case -135:
               case 45:
                  var3 = 1;
                  break;
               case -90:
               case 90:
               case 270:
                  var3 = 5;
                  break;
               case -45:
               case 135:
                  var3 = 0;
                  break;
               case 0:
               case 180:
                  var3 = 4;
               }

               if (var4 < 0) {
                  var4 = -90 - var4;
                  if (var5 != 100) {
                     var5 = -var5;
                  }
               } else {
                  var4 = 90 - var4;
               }

               if (var4 < 0) {
                  var4 += 360;
               }

               var4 %= 360;
               break;
            case 5:
               var3 = 3;
               break;
            case 6:
               var3 = 2;
               break;
            case 100:
               if (!var1.isVisible()) {
                  this.setType(1);
               } else if (!var1.h() && var1.getForeColorTransparency() == 0.0D) {
                  this.setType(0);
                  this.c = true;
               } else {
                  this.setType(2);
                  this.getSolidFill().setColor(var1.getForeColor());
                  this.getSolidFill().a(var1.getBackColor());
                  this.getSolidFill().setTransparency(var1.getForeColorTransparency());
               }

               return;
            default:
               return;
            }

            this.setType(3);
            GradientFill var6 = this.getGradientFill();
            GradientStopCollection var7 = var6.getGradientStops();
            Color var8 = var1.getForeColor();
            double var9 = var1.getForeColorTransparency();
            double var11 = var1.f();
            Color var13 = Color.getEmpty();
            byte var14 = 1;
            double var15 = 0.5D;
            int var17 = 24;
            byte[] var18 = null;
            int var19;
            if (var1.aq() == 8 || var1.aq() == 1073741835 && (var1.d() & 268435696) == 268435696) {
               var15 = 0.5D;
               var19 = var1.d();
               if ((var19 & 256) != 0) {
                  var15 = (double)((var19 & 16711680) >> 16) / 512.0D;
               } else {
                  var15 = 1.0D - (double)((var19 & 16711680) >> 16) / 512.0D;
               }

               var13 = GradientFill.a(var8, var15);
            } else if (var1.ap()) {
               var14 = 2;
               var17 = var1.an();
               var18 = var1.ao();
               if (var17 != 24) {
                  var18 = MsoFillFormatHelper.c(var17);
               }
            } else {
               var14 = 3;
               var13 = var1.getBackColor();
            }

            if (var18 != null) {
               zvj.a(var7, var18, var5 <= 0);
               short var28 = com.aspose.cells.b.a.zc.b(var18, 0);
               if (var14 == 2 && var17 == 24 && var28 == 2) {
                  var14 = 3;
               }
            } else {
               var7 = var6.getGradientStops();
               zakp var29 = new zakp(true);
               zakp var20 = new zakp(true);
               var29.a(2, var8.toArgb());
               var20.a(2, var13.toArgb());
               GradientStop var21 = new GradientStop(var7);
               var21.a = var5 <= 0 ? var20 : var29;
               var21.setTransparency(var5 <= 0 ? var11 : var9);
               var21.setPosition(0.0D);
               var7.a(var21);
               var21 = new GradientStop(var7);
               var21.a = var5 <= 0 ? var29 : var20;
               var21.setTransparency(var5 <= 0 ? var9 : var11);
               var21.setPosition(100.0D);
               var7.a(var21);
            }

            var19 = var5 <= 0 ? 2 : 1;
            if (var5 < 0) {
               var5 += 100;
            }

            int var30 = var7.getCount();
            if (var5 > 0 && var5 < 100) {
               var19 += 2;

               for(int var31 = 0; var31 < var30; ++var31) {
                  GradientStop var22 = var7.get(var31);
                  double var23 = var22.getPosition();
                  var22.setPosition(var22.getPosition() * (double)var5 / 100.0D);
                  if (var31 != var30 - 1) {
                     GradientStop var25 = new GradientStop(var7);
                     var25.a(var22);
                     var25.setPosition(100.0D - var23 * (double)(100 - var5) / 100.0D);
                     var7.a(var30, var25);
                  }
               }
            }

            if (var3 != 3 && var3 != 2) {
               zacn var33 = new zacn();
               var6.b = var33;
               var33.b = var1.b() == 7;
               var6.setAngle((float)var4);
            } else {
               if (var1.j() == 0.5D && var1.k() == 0.5D && var1.l() == 0.5D && var1.m() == 0.5D) {
                  var3 = 2;
               }

               zaco var32 = new zaco();
               var32.a = 1;
               var6.b = var32;
               var32.b = (int)(var1.j() * (double)zml.k);
               var32.c = (int)(var1.k() * (double)zml.k);
               var32.e = zml.k - (int)(var1.l() * (double)zml.k);
               var32.d = zml.k - (int)(var1.m() * (double)zml.k);
            }

            zacl var34 = new zacl();
            var6.a = var34;
            var34.b = var14;
            var34.d = var15;
            var6.d = var17;
            var34.a = var3;
            var34.c = var19;
         }
      }
   }

   MsoFillFormatHelper a(ArrayList var1) {
      if (var1 == null && var1.size() == 0) {
         return null;
      } else {
         zash var2 = new zash(this);
         MsoFillFormatHelper var3 = new MsoFillFormatHelper((Shape)null, var2, this.a);
         a(var1, var2);
         return var3;
      }
   }

   static void a(ArrayList var0, zash var1) {
      byte[] var2 = (byte[])((byte[])var0.get(0));
      byte var3 = 0;
      int var4 = com.aspose.cells.b.a.zc.e(var2, var3 + 2) & '\uffff';
      int var5 = com.aspose.cells.b.a.zc.b(var2, var3) >> 4;
      int var13 = var3 + 8;
      int var6 = var13 + var5 * 6;
      int var7 = 0;
      boolean var8 = false;
      boolean var9 = false;

      for(int var10 = 0; var10 < var5; ++var10) {
         int var14 = com.aspose.cells.b.a.zc.e(var2, var13);
         int var15 = com.aspose.cells.b.a.zc.a(var2, var13 + 2);
         if ((var14 & '\uffff' & '耀') != 0) {
            if (var15 == 0) {
               var13 += 6;
               continue;
            }

            byte[] var11 = new byte[var15];
            int[] var12 = a(var11, var6, var0, var7);
            var6 = var12[0];
            var7 = var12[1];
            var1.a(var14, 4, var11);
         } else {
            var1.a(var14, 0, var15);
         }

         var13 += 6;
      }

   }

   static int[] a(byte[] var0, int var1, ArrayList var2, int var3) {
      int var4 = 0;

      for(boolean var5 = false; var3 < var2.size(); ++var3) {
         byte[] var6 = (byte[])((byte[])var2.get(var3));
         int var7 = var6.length - var1;
         if (var0.length - var4 <= var6.length - var1) {
            var7 = var0.length - var4;
            System.arraycopy(var6, var1, var0, var4, var7);
            var1 += var7;
            break;
         }

         System.arraycopy(var6, var1, var0, var4, var7);
         var1 = 0;
         var4 += var7;
      }

      int[] var8 = new int[]{var1, var3};
      return var8;
   }
}
